package com.xunmall.executors.demo.service;

import com.xunmall.executors.framework.ExecutorGroup;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.Executor;

@Service
public class SayHiService {

	@Resource
	private ExecutorGroup executorGroup;

	private Executor executor;

	@PostConstruct
	public void init() {
		executor = executorGroup.get("sync-executor");
		Assert.notNull(executor);
	}

	public void sayHi() {
		executor.execute(new Runnable() {
			@Override
			public void run() {
				System.out.println("hi");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
	}
}
